Skip to content

fix: accept any realtime fallback host in REST requests - #751

Open
pcbeingused333 wants to merge 1 commit into
ably:mainfrom
pcbeingused333:fix/rest-realtime-fallback-host
Open

pcbeingused333 wants to merge 1 commit into
ably:mainfrom
pcbeingused333:fix/rest-realtime-fallback-host

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

When the realtime connection is established through a fallback host, REST requests on the same client can fail with ValueError: list.remove(x): x not in list.

Cause: the realtime connection manager tries every fallback host (5 by default), and the transport saves the one that connected in options.fallback_host (RTN17e). Http.get_hosts() then calls hosts.remove(host) on options.get_hosts(), which holds only the primary and the first http_max_retry_count (3 by default) fallbacks. If the saved host is one of the other two, remove raises before any request is sent.

Fix: put the saved host first, whether or not it was already in the list, and keep the list the same length, so http_max_retry_count still bounds the number of attempts. The order is unchanged when the host was already in the list. When it was not, the last fallback is dropped to make room.

Tests: added a unit test in test/unit/http_test.py that saves each of the 5 fallback hosts in turn. On main the 2 cases outside the REST list fail with the ValueError; all 5 pass with the change. test/uts/rest/unit and the realtime connection and client unit tests pass, and ruff check is clean.

Reproduction

from ably.pubsub.server import create_http_client
client = create_http_client(token='foo')
client.options.fallback_host = client.options.get_fallback_hosts()[-1]  # what the realtime transport does
client.http.get_hosts()  # ValueError

This PR was prepared with the help of an AI assistant (Claude); the change and tests are disclosed here as AI-assisted work.

Summary by CodeRabbit

  • Bug Fixes
    • Improved fallback host selection to avoid errors when a saved fallback host is absent and prevent duplicate hosts in the results.
  • Tests
    • Added coverage for fallback host ordering, uniqueness, and list size.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Http.get_hosts now places the saved fallback host first, removes duplicates, and preserves the original host-list length. A parameterized unit test checks this behavior for all five realtime fallback hosts.

Changes

REST host selection

Layer / File(s) Summary
Fallback host ordering
ably/pubsub/request/http.py, test/unit/http_test.py
get_hosts prepends the saved host, removes duplicate occurrences, and limits the result to the original list length. The test checks ordering, list length, and duplicates for all five realtime fallback hosts.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: ttypic, owenpearson

Merge Risk: Minimal · up to 4293f

This fixes REST requests failing when a realtime connection has fallen back to a host outside the REST retry list. The change is small, covered by a unit test for all five fallback hosts, and low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: REST requests now accept any realtime fallback host. The raw summary confirms Http.get_hosts now places the saved fallback host first instead of raising ValueError whe…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: REST requests now accept any realtime fallback host. The raw summary confirms Http.get_hosts now places the saved fallback host first instead of raising ValueError when it is absent, and a parameterized test covers all five fallback hosts. The title is specific and matches the changeset and the stated objectives.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the hosts in line
The saved one hops to the front
No duplicates crowd the list
Five fallback hosts pass the test
The list stays the same length
Then off the rabbit goes to rest

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b1d9eb4d-7a2f-4f15-8cde-64d61621170e
Commits

Reviewing files that changed from the base of the PR and between 2435510 and 4293f9a.

Files selected for processing: 2

  • ably/pubsub/request/http.py
  • test/unit/http_test.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant